package com.example.javamaday.leetcode;

public class LeetCodeTest0704 {

    public static void main(String[] args) {
        int search = new LeetCodeTest0704().search(new int[]{-1,0,5}, -1);
        System.out.println("Result :" + search);
    }

    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length -1;
        while (left <= right) {
            if (left == right) {
                if (nums[left] == target) {
                    return left;
                }
                return -1;
            }
            int mid = left + (right-left)/2;
            if (nums[mid] == target) {
                return mid;
            }
            if (nums[mid] > target) {
                right = mid -1;
            } else {
                left = mid + 1;
            }
        }
        return -1;
    }


}
